package com.bjc.core.controller;

import java.util.List;

import com.bjc.base.core.annotation.Permission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bjc.base.bean.ResultVO;
import com.bjc.base.bean.PermissionTreeVO;
import com.bjc.base.core.ResultGenerator;
import com.bjc.base.core.annotation.PermissionPath;
import com.bjc.core.bean.request.DepartmentReqVO;
import com.bjc.core.bean.request.RolePermissionReqVO;
import com.bjc.core.bean.response.DimensionItemDataVO;
import com.bjc.core.service.IDepartmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 维度控制器
 * 
 * @author 许自辉
 * @date 2017年8月21日
 */

@RestController
@RequestMapping("api/cloud")
@PermissionPath("系统管理/部门")
@Api(value = "dimension-api", tags = { "部门相关接口" })
public class DepartmentController {

	@Autowired
	private IDepartmentService departmentService;

	@ApiOperation("分页查询未拥有数据范围的部门")
	@Permission("department:dimensionItemData:findPage")
	@GetMapping("department/dimensionItemData/findPage")
	public ResultVO getDimensionPage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize,
			DepartmentReqVO reqVO) {
		PageHelper.startPage(pageNum, pageSize);
		List<DimensionItemDataVO> dimensionVOs = departmentService.getDimensionItemData(reqVO);
		return ResultGenerator.getSuccess(new PageInfo<DimensionItemDataVO>(dimensionVOs));
	}

	@ApiOperation("查询部门数")
	@GetMapping("department/findTreeHave")
	public ResultVO findTreeHave(@Validated RolePermissionReqVO rolepermissionReqVO) {
		List<PermissionTreeVO> treelist = departmentService.getTree(rolepermissionReqVO);
		treelist = PermissionTreeVO.getDeptTree(treelist);
		return ResultGenerator.getSuccess(treelist);
	}
}
